package jwt.lab02;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.Session;
import javax.mail.MessagingException;
import java.util.Properties;

public class SendMail {

	public static void main(String[] args) throws MessagingException {
		Properties props = Utils.loadProperties(Utils.PROPERTIES_FILE);

		Session session = Session.getDefaultInstance(props, null);

		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(props.getProperty("mail.smtp.from")));

		message.addRecipient(Message.RecipientType.TO, new InternetAddress(props.getProperty("mail.to")));
		message.setSubject(props.getProperty("mail.subject"));
		message.setText(props.getProperty("mail.content"));

		System.out.println("Sending message...");

		Transport transport = session.getTransport();
		transport.connect(props.getProperty("mail.smtp.user"), props.getProperty("mail.smtp.password"));
		transport.sendMessage(message, message.getAllRecipients());
		transport.close();

		System.out.println("[ OK ]");
	}

}
